package org.zzz.hepotaiya.container.spring;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.zzz.hepotaiya.container.IContainer;

public class SpringContainerWrapper implements IContainer {

	ApplicationContext context;
	
	public void setApplicationContext(ApplicationContext context) {
		this.context = context;
	}
	
	public Object getObject(String componentName) throws Exception {
		if (StringUtils.isEmpty(componentName)) {
			return null;
		}
		return this.context.getBean(componentName);
	}

	public Object getObject(Class clazz) throws Exception {
		return this.context.getBean(StringUtils.uncapitalize(clazz.getSimpleName()));
	}

}
